﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;

/// <summary>
/// Summary description for GioHang
/// </summary>
[Serializable]
public class GioHang
{
    List<ChiTietDonHang> list = new List<ChiTietDonHang>();

    public List<ChiTietDonHang> List
    {
        get { return list; }
        set { list = value; }
    }
    public void Add(String id)
    {
        bool check = true;
        foreach (ChiTietDonHang item in list)
        {
            if (id == item.Sanpham.Sanphamid)
            {
                item.Soluong++;
                check = false;
            }
        }
        if (check)
        {
            ChiTietDonHang ct = new ChiTietDonHang();
            SanPham sp = new SanPham();
            SanPhamDA spda = new SanPhamDA();
            sp = spda.getSanPhamByID(id);
            ct.Sanpham = sp;
            ct.Soluong = 1;
            HinhAnh ha = new HinhAnh();
            HinhAnhDA hada = new HinhAnhDA();
            ha = hada.getTop1bySPID(id);
            ct.Hinhanh = ha;
            list.Add(ct);
        }
    }
    public void Delete(String id)
    {
        for (int i = 0; i < List.Count; i++)
        {
            if (List[i].Sanpham.Sanphamid == id)
            {
                List.RemoveAt(i);
                i--;
            }
        }
        
    }
    public void Update(int id, int soluong)
    {
        foreach (ChiTietDonHang item in list)
        {
            if (item.Id == id)
            {
                item.Soluong = soluong;
            }
        }
    }
    public float TongThanhTien()
    {
        float tong = 0;
        foreach (ChiTietDonHang item in List)
        {
            tong = item.Thanhtien + tong;
        }
        return tong;
    }
	
}